<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <div>first div</div>
    <div>second div</div>
    <div class="empty"></div>
    <div>third div<div>inner div</div></div>
    <ul id="result"></ul>
    <script>
        (function () {
            var divElements = document.getElementsByTagName('div');
            var src, liElement, attrs;

            for(var i = 0, len = divElements.length; i < len; i++) {
                src = divElements[i];
                liElement = document.createElement('li');
                attrs = src.attributes;
                for(var j = 0, k = attrs.length; j < k; j++) {
                    liElement.setAttribute(attrs[j].name, attrs[j].value);
                }
                
                liElement.innerHTML = src.innerHTML;
                document.getElementById('result').appendChild(liElement);
            }
        }());
    </script>
</body>
</html>